package io.renren.modules.clothingorder.controller;

import com.alibaba.fastjson.JSONObject;
import io.renren.common.utils.PageData;
import io.renren.common.utils.Result;
import io.renren.modules.clothingorder.dto.ClothingOrderDTO;
import io.renren.modules.clothingorder.service.ClothingOrderService;
import io.renren.modules.clothingorder.vo.ClothingOrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


/**
 * 订单表
 *
 * @author lzy lzy
 * @since 1.0.0 2021-08-30
 */
@RestController
@RequestMapping("sys/clothingorder")
@Api(tags="订单表")
public class ClothingOrderController {

    @Autowired
    private ClothingOrderService clothingOrderService;

    @ApiOperation("订单--(顾客)报价环节")
    @PostMapping("add")
    public Result<Map<String,Object>> addClothingType(@RequestBody ClothingOrderDTO dto) {
        clothingOrderService.addOrder(dto);
        return new Result<Map<String, Object>>();
    }

    @ApiOperation("设计师上传图稿环节")
    @PostMapping("updesginerpic")
    public Result<Map<String,Object>> upDesginerPic(@RequestBody ClothingOrderDTO dto) {
        clothingOrderService.upDesginerPic(dto);
        return new Result<Map<String, Object>>();
    }

    @ApiOperation("获取登录用户的订单信息")
    @GetMapping("orderpage")
    public Result<PageData<ClothingOrderVO>> getOrderPage(@RequestParam Map<String, Object> params) {
        PageData<ClothingOrderVO> pageData = clothingOrderService.getOrderPage(params);
        return new Result<PageData<ClothingOrderVO>>().ok(pageData);
    }

    @ApiOperation("统计已定制订单数量、最多服装类型")
    @GetMapping("statistics")
    public Result<JSONObject> getStatistics(@RequestParam Map<String, Object> params) {
        JSONObject map = clothingOrderService.getStatistics(params);
        return new Result<JSONObject>().ok(map);
    }

    @ApiOperation("获取历史订单服装列表")
    @GetMapping("gethistorypage")
    public Result<PageData<JSONObject>> getHistoryPage(@RequestParam Map<String, Object> params) {
        PageData<JSONObject> pageData = clothingOrderService.getHistoryPage(params);
        return new Result<PageData<JSONObject>>().ok(pageData);
    }

    @ApiOperation("改变订单状态")
    @PostMapping("changestatus/{id}/{status}")
    public Result<Map<String,Object>> changeStatus(@PathVariable Long id,@PathVariable Integer status) {
        clothingOrderService.changeStatus(id,status);
        return new Result<Map<String, Object>>();
    }

}
